local puwei = fk.CreateSkill {
    name = "ys__puwei",
}

Fk:loadTranslationTable {
    ["ys__puwei"] = "蒲苇",
    [":ys__puwei"] = "每回合限一次，当你于一个阶段内受到伤害时，你可以防止此伤害，然后你须弃置等同伤害值张手牌或失去所有体力。然后你本阶段再次受到伤害时重复此流程；本阶段结束时你摸X张牌（X为你本阶段因此弃置的牌数+1）。",
}

puwei:addEffect(fk.DamageInflicted, { --确认是否发动技能
    can_trigger = function(self, event, target, player, data)
        return target == player and player:hasSkill(puwei.name) and player:getMark("puwei_") == 0 and player:usedSkillTimes(puwei.name, Player.HistoryTurn) == 0
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        room:setPlayerMark(player, "puwei_", 1)
    end,
})

puwei:addEffect(fk.DamageInflicted, { --发动技能后弃牌
    is_delay_effect = true,
    can_trigger = function(self, event, target, player, data)
        return target == player and player:hasSkill(puwei.name) and player:getMark("puwei_") > 0
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local damage = data.damage
        data:preventDamage()
        if (#player:getCardIds("h") < damage) then
            room:loseHp(player, player.hp, puwei.name)
        else
            local card = room:askToChooseCards(player, { target = player, flag = "h", skill_name = puwei.name, min = damage, max = damage })
            room:throwCard(card, puwei.name, player, player)
            room:addPlayerMark(player, "puwei_", damage)
        end
    end,
})

puwei:addEffect(fk.EventPhaseEnd, { --阶段结束时摸牌
    is_delay_effect = true,
    can_trigger = function (self, event, target, player, data)
        return player:getMark("puwei_") > 0
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        player:drawCards(player:getMark("puwei_"), puwei.name)
        room:setPlayerMark(player, "puwei_", 0)
    end,
})

return puwei